package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.model.FinanceResult;
import com.lecture.java8.excel.model.Result;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Test0319 {
    public static void main(String[] args) {
        String dataResultFileName = "D:\\study\\tmp\\0319\\1\\difi2222.xlsx";
        DemoDataListener<Result> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Result.class,dataResultListener).sheet().doRead();
        List<Result> resultList = dataResultListener.getDataList();

        Map<String, String> resultMap = resultList.stream().collect(Collectors.toMap(r -> r.getYear() + "-" + r.getYear(), Result::getIndex));


        String dataFileName = "D:\\study\\tmp\\0319\\1\\不带st不带金融.xlsx";
        DemoDataListener<FinanceResult> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataFileName, FinanceResult.class,dataListener).sheet().doRead();
        List<FinanceResult> financeList = dataListener.getDataList();
        for (FinanceResult finance : financeList) {
            String yearStr = finance.getReptdt().substring(0, 4);
            finance.setIndex(resultMap.get(yearStr + "-" + finance.getCity()));
        }

        EasyExcel.write("D:\\study\\tmp\\0319\\1\\result.xlsx", FinanceResult.class)
                .sheet("a").doWrite(financeList);

    }
}
